<template>
  <div class="app-container">

    <div class="button" style="padding-bottom:0.5rem">
      <div class="grid-content bg-purple-dark">
        <el-row>
          {{"部门:"}}
          <el-select v-model="depName" placeholder="请选择部门" clearable  @change="find(currentPage=1,depName)"
                     style="width:15%">
            <el-option
              v-for="item in departmentList"
              :key="item.depName"
              :label="item.depName"
              :value="item.depName"
            ></el-option>
          </el-select>
        </el-row>
      </div>
    </div>

    <el-table
      element-loading-text="Loading"
      :data="employeesList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <el-table-column label="员工姓名" align="center">
        <template slot-scope="scope">{{ scope.row.userName }}</template>
      </el-table-column>
      <el-table-column label="部门" align="center">
        <template slot-scope="scope">{{ scope.row.depName }}</template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="choose(scope.row.userId)">查看权限</el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>
  </div>
</template>

<script>
  import $ from "@/api/permissSet"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        depName:"",
        employeesList: [],
        departmentList: [],
      }
    },
    created() {
      // 员工列表
      this.fetchData()
      // 部门列表
      $.tbDmReturnList().then(res => {
        this.departmentList = res.data
      })
    },
    methods: {
      fetchData() {
        this.currentPage = 1
        $.tbAuthUserPageInfo({
          pageIndex: this.currentPage,
          pageSize: this.pageSize
        }).then(res => {
          this.employeesList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          console.log(this.employeesList)
        })
      },

      choose(id) {
        this.$router.push({
          path: "choose",
          query: {id: id}
        });
      },

      find(pageIndex,name){
        $.tbAuthUserPageInfo({
          pageIndex: pageIndex,
          pageSize: this.pageSize,
        }).then(res => {
          this.employeesList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }
          // console.log(res.data)
        })
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage,this.depName)
        } else this.find(this.currentPage,this.depName)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage,this.depName)
        } else this.find(this.currentPage,this.depName)
      },
    }
  }
</script>
